﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Meqs.Entity;
using System.Collections.Generic;
using System.Web.Services;
using Meqs.Utilities;
using Meqs.Logic.Interface;

public partial class Moral_Teacher_Reprots_ClassEvalMonth : System.Web.UI.Page
{
    protected string KeyWord
    {
        get
        {
            return ClassEvalHistory.Class_Month_Notes;
        }
    }
    protected IList<UserProjectScore> ups = null;
    protected IList<ClassEvalType> evaltype = null;
    protected IList<ClassEvalItem> evalitem = null;
    protected IList<VClasssInfo> vclasses = new List<VClasssInfo>();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnBind_Click(object sender, EventArgs e)
    {
        try
        {
            Hashtable ht = new Hashtable();
            ht.Add("SchoolMark", Common.GetConstSchoolMark());
            ht.Add("KeyWord", KeyWord);
            ht.Add("SchoolYear", Convert.ToInt32(Request.Form[schoolYear.UniqueID].ToString()));
            ht.Add("Term", Convert.ToInt32(Request.Form[schoolTerm.UniqueID].ToString()));
            evaltype = Container<IClassEvalCatchLogic>.Instance.FindKeyWordTypeInfo(ht);
            evalitem = Container<IClassEvalCatchLogic>.Instance.FindKeyWordItemInfo(ht);

            ht.Add("Year", Convert.ToInt32(Request.Form[year.UniqueID].ToString()));
            ht.Add("Month", Convert.ToInt32(Request.Form[yearmonth.UniqueID].ToString()));
            ups = Container<IClassEvalCatchLogic>.Instance.FindKeyWordMonthItemInfo(ht);
            ht = new Hashtable();
            ht.Add("SchoolMark", Common.GetConstSchoolMark());
            ht.Add("Grade", Convert.ToInt32(Request.Form[schoolGrade.UniqueID].ToString()));
            ht.Add("SchoolYear", Convert.ToInt32(Request.Form[schoolYear.UniqueID].ToString()));
            vclasses = Container<ITermInfoLogic>.Instance.FindYearClasses(ht);
            Repeater1.DataSource = vclasses;
            Repeater1.DataBind();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    protected string GetHeader()
    {
        string str = "<tr><th rowspan=2>班级</th>";
        int index = 1;
        foreach (ClassEvalType ty in evaltype)
        {
            int num = GetTypeNum(ty.RID);
            if (num>0)
            {
                str += "<th colspan=" + num + ">" + ty.Caption + "</th>";
            }
            
        }
        str += "<th rowspan=2 onclick='sort({index})'>总计<span id='img{index}'><img src='../../Common/images/1.gif' /></span></th></tr>";
        str += "<tr>";
        foreach (ClassEvalType ty in evaltype)
        {
            foreach (ClassEvalItem cei in evalitem)
            {
                if (cei.TypeID == ty.RID)
                {
                    str += "<th onclick='sort(" + index + ")'>" + cei.Caption + "<span id='img" + index + "'></span></th>";
                    index++;
                }
            }

        }
        str += "</tr>";
        str = str.Replace("{index}", index.ToString());
        return str;
    }
    protected int GetTypeNum(int typeid)
    {
        int num = 0 ;
        foreach (ClassEvalItem cei in evalitem)
        {
            if (cei.TypeID == typeid)
            {
                num++;
            }
        }
        return num;
    }
    protected string GetTeacher(int id, string name)
    {

        string str = "<tr onclick='SetHightLight(this);'><td >" + name + "</td>";
        double full = 0;
        foreach (ClassEvalType ty in evaltype)
        {
            foreach (ClassEvalItem cei in evalitem)
            {
                if (cei.TypeID == ty.RID)
                {
                    object score = GetScore(id, cei.RID);
                    if (score != null)
                    {
                        full += Convert.ToDouble(score);
                        str += "<td >" + Math.Round(Convert.ToDouble(score), 1) + "</td>";
                    }
                    else
                    {
                        str += "<td ></td>";
                    }
                }
            }

        }
        str += "<td >" + Math.Round(full, 1) + "</td>";
        str += "</tr>";
        return str;
    }

    protected object GetScore(int classid,int itemid)
    {

        foreach (UserProjectScore cei in ups)
        {
            if (cei.UserID == classid && cei.ProjectID == itemid)
            {
                return cei.Score;
            }
        }
        return null;
    }
    [WebMethod]
    public static string GetExcel(ExcelTableCell[][] cells)
    {
        string temp_path = HttpContext.Current.Server.MapPath("../../../");
        string save_path = temp_path + "\\download\\" + "班级奖惩.xls";
        HttpContext.Current.Session["filepath"] = save_path;
        Meqs.Utilities.ExcelUtil.ExcelExport(save_path, "班级奖惩", 2, 0, cells);
        return "";
    }
}
